<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/8/25
 * Time: 14:21
 */
if(!session_id()) session_start();
header("Access-Control-Allow-Origin:*");
header('Access-Control-Allow-Methods:POST,GET');
header('Access-Control-Allow-Headers:x-requested-with,content-type');

require_once('dbServerConnect.php');
$con = new DB();
$link = $con->mySqlServer();

if (!$link) {
    echo '数据库连接失败';
    return;
}

// if(!isset($_SESSION["username"])) {
// 	echo "非法访问";
// 	return;
// }

// 获取前端axios post 请求的json数据
$jsonData = file_get_contents("php://input");
// json_decode — 对 JSON 格式的字符串进行解码 true：输出为数组，不写则为对象
$decodeData = json_decode($jsonData, true);


// 判断editForm表单字段是否存在，和editForm里面的字段不能为空
if(isset($decodeData['editForm']) && !empty($decodeData['editForm']['title']) && !empty($decodeData['editForm']['description']) && !empty($decodeData['editForm']['container']) && !empty($decodeData['editForm']['tag']) && !empty($decodeData['editForm']['username'])) {
    $editForm = $decodeData['editForm'];
	$username = $decodeData['editForm']['username'];
    $istop = $decodeData['editForm']['isTop'];
    $isHide = $decodeData['editForm']['isHide'];
    $title = str_replace("'", "''",$editForm['title']);
    $description  = str_replace("'", "''",$editForm['description']);
    $container = str_replace("'", "''",$editForm['container']);
    $tag = str_replace("'", "''",$editForm['tag']);

    $sql = "insert into  blog_container(author,title,description,container,createdate,tag,istop,ishide) values ('$username','$title','$description','$container',now(),'$tag','$istop','$isHide')";

    $executeSql = mysqli_query($link,$sql) or  die(mysqli_error($link));

    if(!$executeSql) {
        echo $executeSql;
        return;
    }
    echo $executeSql;
}
else {
    echo "不能为空";
}





